package com.ophiux.cs.application.consultOrder.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consultOrder.dto.GetConsultOrderByRecordIdRequest;
import com.ophiux.cs.application.consultOrder.dto.GetConsultOrderByRecordIdResponse;
import com.ophiux.cs.application.consultOrder.service.IGetConsultOrderByRecordIdAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultOrder.model.entity.CSOnlineRecords;
import com.ophiux.cs.domain.consultOrder.repositories.ICSOnlineRecordRepository;
import com.ophiux.utils.common.ShiftUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class GetConsultOrderByRecordIdAppService implements IGetConsultOrderByRecordIdAppService{
	@Autowired
	ICSOnlineRecordRepository csOnlineRecordRepository;
	
	@Override
	public Result<GetConsultOrderByRecordIdResponse> GetConsultOrderByRecordId(GetConsultOrderByRecordIdRequest dto) {
		GetConsultOrderByRecordIdResponse resp = new GetConsultOrderByRecordIdResponse();
		try {
			if(!dto.isParamValid()) {
				return Result.fail(ResultEnum.requestParamFail);
			}
			
			CSOnlineRecords record = csOnlineRecordRepository.getRecordById(dto.getRECORD_ID());
			
			resp = (GetConsultOrderByRecordIdResponse) ShiftUtils.objToNewObj(record, GetConsultOrderByRecordIdResponse.class);
			
		} catch (Exception e) {
			log.info("程序异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return Result.success(resp);
	}

}
